Skip to content

Use the declared native reader budget for captured Inbox pages - #9095

Merged
loopx-agent merged 1 commit into
mainfrom
codex/inbox-recovery-page-budget
Nov 21, 2026
Merged

loopx-agent merged 1 commit into
mainfrom
codex/inbox-recovery-page-budget

Conversation

@loopx-agent

Copy link
Copy Markdown
Collaborator

Outcome

Large Markdown Manager Inbox responses use the native 64,000-byte reader profile when the caller declares it. The Markdown opening has a 12,000-byte cap. A caller without the declaration also uses 12,000-byte continuations. Both reader commands keep the original executable, capture digest and byte cursors.

Validation

  • Two synthetic multilingual captures totaling 388,297 source bytes took 37 reader calls at 12,000 bytes and 8 at 64,000 bytes. Complete reader output fell from 432,417 to 411,997 bytes. The source bytes and Inbox cursors matched. Direct recovery used the same captures. A missing reader reference and a wrong digest each returned an error without source content.
  • The production CLI tests used File and SQLite at both widths. They checked complete UTF-8 coverage, stable receipts, compact-reference loss and direct recovery. Targeted Ruff checks passed.
  • The wider context suite had 283 passes and two skips on this head. Its eight failures reproduced on the verified base, covering resume work-option assertions and native projection assertions.
  • The measurements cover reader calls and bytes. Installed host adoption, model retention and token costs are unmeasured.
  • Quick premerge on the committed head passed all six direct checks and four selected checks.

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: model_agent · Gemini · Google (self_reported)

Approval conclusion (author-owned PR; GitHub blocks formal self-approval)

对精确提交 dddc3906f9a85d8b1a1a8fa235fbc2d636a5fb89 完成独立审查。未发现阻断主干合并的缺陷。

动机 / Motivation

在声明了原生 64,000 字节上下文读取配置的宿主会话中执行 manager-inbox read --format markdown 的调用方(例如受管 worker 在读取超长收件箱分页时)。

改动前即使环境已声明 LOOPX_CONTEXT_PAGE_OUTPUT_BYTES=64000,_read_markdown 仍把捕获读取命令硬编码在 12,000 字节预算(实测 149,251 字节多语言捕获需 14 次读取、总输出 157,744 字节);改动后仅当环境变量精确匹配声明的 64,000 字节上限时,把 direct_command 与 short_command 提升至 64,000 字节(同捕获降至 3 次读取、151,814 字节),开篇清单与未声明配置路径仍严格保持在 12,000 字节以内。

已声明 LOOPX_CONTEXT_PAGE_OUTPUT_BYTES=64000 时,manager-inbox read --format markdown 开篇仍不超过 12,000 字节(实测 1,971 字节,直接回退路径 1,534 字节),其 command 与 recovery_command 使用 --page-bytes 64000 --max-page-output-bytes 64000 并经 next_command 保持;未设置或设置为非 64000 值(如 7900、999999、非法字符串)时保持 12,000 字节上限。

本 PR 不改变 manager-inbox 的 JSON 模式输出、不提升 Markdown 开篇自身的 12,000 字节封顶、不修改 quota context-read 默认预算,也不负责验证未继承 shell 环境变量的 Codex App 宿主的实际模型 token 保留效果。

改动思路 / Approach

将工具预算感知留在 CLI 表现层 _read_markdown 内,直接复用 native_context_page_budget、环境变量常量与 context_capture_read_command,不改动领域权限或持久化收据语义。仅当环境精确声明 LOOPX_CONTEXT_PAGE_OUTPUT_BYTES=64000 时放宽 manager-inbox read --format markdown 捕获页读取参数至 64,000 字节;开篇边界及未声明/异常环境值维持 12,000 字节。

控制流入口仍在 handle_manager_inbox 的 Markdown 分支(loopx/cli_commands/manager_inbox.py),当序列化正文超过 NATIVE_CONTEXT_FIRST_READ_FALLBACK_BYTES(12,000 字节)且未超出 MAX_REQUEST_BYTES 时,先通过 capture_context_recovery 将完整分页视图写入私有只读捕获文件,再从 native_context_profile.native_context_page_budget() 读取原生 64,000 字节配置。与 quota_capture(面向专用原生上下文通道、无条件允许 64,000 字节读取)不同,manager-inbox 面向通用 CLI/工具调用方,因此仅在 os.environ.get(NATIVE_CONTEXT_OUTPUT_ENV) == str(output_bytes) 时把 64,000 字节配置传入 context_capture_read_command,从而在安全降级(12,000 字节)与减少原生宿主往返之间取得最小侵入平衡。

具体改动 / Changes

对照既有规范文档 docs/reference/required-work-context.md(提交 62784ecc532585d4f277dd94fe9a169fb95b5050),逐条核对当前实现:

  • NCTX-OPEN-12K(已实现 / implemented):未声明预算时的首读与 Markdown 开篇清单维持 12,000 字节上限,由 loopx/cli_commands/manager_inbox.py _read_markdown(第 119、172–176 行)与 tests/test_delegation_turn_context.py 覆盖。
  • NCTX-READER-64K(已实现 / implemented):当 codex_context 生成的配置声明 LOOPX_CONTEXT_PAGE_OUTPUT_BYTES=64000 时,捕获读取命令使用 64,000 字节分页上限,由 _read_markdown(第 142–166 行)与 tests/test_delegation_turn_context.py 实测覆盖。
  • NCTX-FALLBACK-12K(已实现 / implemented):缺少或携带其他环境变量声明时退回 12,000 字节并在 reference_file 不可用时保留 recovery_command 同预算恢复,由 _read_markdown(第 145–146、167–171 行)与反向探针验证。

改动文件统计(基线 45c015ffd9c9065b3af533e0abf103170627d15f 至 dddc3906f9a85d8b1a1a8fa235fbc2d636a5fb89):共 3 个文件 +41/-8(生产代码 1 个文件 +12/-3,测试 1 个文件 +20/-5,能力说明文档 1 个文件 +9/-0)。

关键代码讲解

  1. _read_markdown:保持 limit = NATIVE_CONTEXT_FIRST_READ_FALLBACK_BYTES(12,000)不变用于约束 size <= limit 及开篇输出长度校验;仅当 os.environ.get(NATIVE_CONTEXT_OUTPUT_ENV) == str(output_bytes) 时将 native_context_page_budget() 返回的 (64000, 64000) 同时传给 direct_command 与 short_command。任何非 "64000" 值(未设置、"7900"、"999999"、非法文本)均安全回退为 12000,避免受外部环境注入非法整数或超出未知工具截断上限。
  2. native_context_page_budget:既有原生传输配置所有者,提供 (64000, 64000) 与 NATIVE_CONTEXT_OUTPUT_ENV 常量;PR 复用既有定义,未新增重复配置键。
  3. test_unbound_cli_first_read_leaves_inbox_rows_to_its_required_read:将端到端 CLI 用例参数化覆盖 reader_output_bytes ∈ [12_000, 64_000] 及 provider ∈ ["file", "sqlite"],核验开篇输出 ≤ 12,000、两套命令参数一致、next_command 续页延续预算、以及删掉引用文件后经 recovery_command 按相同预算恢复完整 UTF-8 字节与摘要。

对主干的风险 / Risks

  • 环境精确匹配与未继承环境权衡:仅当 LOOPX_CONTEXT_PAGE_OUTPUT_BYTES 精确等于 "64000" 时启用 64,000 字节分页。若上游未来修改 NATIVE_CONTEXT_PAGE_OUTPUT_BYTES 或某个宿主 shell 未继承 shell_environment_policy.set,读取器会自动退回安全的 12,000 字节上限,不会触发截断;但也不会在未继承该变量的 App shell 中自动享受 64,000 字节分页。
  • 验证矩阵与基线失败归因:
    • 核心与相邻回归测试(tests/test_delegation_turn_context.py、tests/test_manager_context_roundtrip.py、tests/control_plane/test_context_read_reference.py):PASS(256 通过,2 跳过;包含 File/SQLite × 12,000/64,000 参数化及错误引用恢复)。
    • 反向探针实测(未修改工作树):验证 LOOPX_CONTEXT_PAGE_OUTPUT_BYTES 为未设置 / "7900" / "999999" / "not-a-number" 时均回退 12000(开篇 1,971 字节),设为 "64000" 且 private_capture_supported()=False 时 direct_opening 回退 1,534 字节仍 ≤ 12,000;对 149,251 字节多语言捕获,12,000 模式需 14 次读取(157,744 字节),64,000 模式降至 3 次读取(151,814 字节)且反序列化完整一致。
    • 静态检查与预合并门禁:ruff check(PASS)、scripts/check_rfc_bilingual.py(PASS)、loopx canary premerge --tier quick(PASS:6 项直接检查 + 3 项目录 canary + loopx check 公开边界扫描全通过)。mypy 默认目标在未修改的 interaction_contract.py:1004 有 1 项与基线 45c015ffd9c9065b3af533e0abf103170627d15f 完全相同的预存报错;对 manager_inbox.py 单独运行 mypy --follow-imports=silent 的 16 项报错也全部与基线 45c015ffd9c9065b3af533e0abf103170627d15f 一致,未引入新错误。
    • 诊断性用例对照:tests/control_plane/test_context_delivery_cli.py 出现 8 项失败(4 项 todo_fixture_settlement 与 4 项 quota.handoff_decision AttributeError),已在不可变基线 45c015ffd9c9065b3af533e0abf103170627d15f 上运行相同命令复现出完全一致的失败签名,属 pre_existing_unrelated,非本 PR 引入。

我的整体评价 / Verdict

visual_review 不适用:本次改动仅涉及 loopx/cli_commands/manager_inbox.py、loopx/capabilities/manager_context/README.md 与 tests/test_delegation_turn_context.py,无前端或渲染 UI 变更。(未验证范围:none,不适用真实宿主模型端到端 token/留存收益实测,仅作局部 CLI/字节统计)。

problem_context 评估为 goal_achieved:对长程执行(long_horizon)在声明 64,000 字节上限时减少捕获分页往返,对普通或未配置调用方维持 12,000 字节 user_experience 安全性;可观测语义向后兼容(未声明路径完全等价,声明路径仅在已声明环境按设计提升读取分页预算)。代码量(+12/-3 生产代码)与架构边界匹配,复用现有 native_context_page_budget 与 NATIVE_CONTEXT_OUTPUT_ENV,未新增状态或词汇。未在本工作树中对真实安装版 Codex 宿主进行多轮模型保留实测(属已知边界内的残余未测项)。

English verdict: APPROVE on exact head dddc390; the declared native 64,000-byte Inbox capture reader budget works with verified 12,000-byte fallback, clean targeted tests (256 passed, 2 skipped), ruff, and quick canary premerge, while the 8 context_delivery_cli failures reproduce identically on base 45c015f.

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: model_agent · gpt-6.2-sol · OpenAI (runtime_reported, xhigh)

Approval conclusion (author-owned PR; GitHub blocks formal self-approval)

动机 / Motivation

使用 LoopX Manager Inbox Markdown 查看长委派或后续结果的操作者和 Agent。 在调用方明确声明 64,000 字节能力时,长收件箱捕获此前仍按 12,000 字节分页。读完同一份资料需要更多工具往返。 首段继续限制在 12,000 字节。仅明确声明 64,000 字节的调用方使用该读取页宽,拿到相同的完整源字节和后续游标。 本次只验证 Inbox 的 CLI 传输。正式安装宿主是否继承环境变量、多轮模型是否完整接收、token 和端到端成本尚未测量。

改动思路 / Approach

Manager Inbox 维持内容及回执所有权,重用原生 profile 和现有同一捕获读取器,只选择后续页宽。 实现边界在 loopx/cli_commands/manager_inbox.py。打开长收件箱时,原 CLI 先取得已经按范围读取的页面,再把完整内容存入原私有捕获。调用方的工具预算只影响读取命令怎样切页。开篇、正常续页、短引用丢失后的直达恢复仍指向同一 SHA 和原命令。 工作上下文规范 捕获入口

具体改动 / Changes

精确头 dddc3906f9a85d8b1a1a8fa235fbc2d636a5fb89,基线 45c015ffd9c9065b3af533e0abf103170627d15f。三文件新增 41 行、删除 8 行,当前主干 3d15059fef 干净整合。

  • opening-bound。申请宽页后的 Markdown 开篇及普通开篇都在 12,000 字节以内。
  • same-capture。三棵源码树在人工构造的中文、转义符和 emoji 混合页上读回相同 UTF-8 字节、SHA、request、operation 和 child 游标。同一份 162,943 字节多语言捕获从 17 次读取降到 3 次,工具输出合计从 197,034 降到 188,244 字节。
  • bounded-reader。真实 before-work CLI 在 File、SQLite 和两种页宽下验证入口、回执及短引用恢复。原 CLI 选择、页指针和补读继续沿既有 owner。

关键代码讲解

  • _read_markdown 在原 scoped read 已取得数据后决定是否输出捕获开篇,同时控制该开篇的输出上限和两种读取命令的独立预算。 Markdown 输出
  • native_context_page_budget 提供现有宽读配置,只有精确环境声明才用于 Inbox 捕获。通用调用方落回同一 12,000 字节路径。 Transport profile 条件分支
  • test_unbound_cli_first_read_leaves_inbox_rows_to_its_required_read 通过实际 CLI 读回两种存储下的游标和完整原请求。 回归矩阵

对主干的风险 / Risks

缺声明、错误声明与未知声明保留 12,000。短引用丢失能用直达命令恢复原摘要,错误摘要拒绝且不返回内容。 精确头和整合树分别通过四种 File/SQLite 页宽组合。更宽的相关套件在精确头 248 项通过、2 项跳过,整合树 258 项通过、2 项跳过。精确头另有 8 个 native_files agenda 用例失败,旧基线复现相同的既有 instruction 比较差异,当前整合通过。隔离 checkout 的原生 quick premerge 通过 6 项直接检查和 4 项选中检查。 Ruff、diff whitespace 均通过,未查询托管 CI。 兼容性说明

我的整体评价 / Verdict

APPROVE。 当前变更减少了大捕获的本地读取往返,保持受限调用方的开篇、原始字节、作用范围及失败后原捕获恢复。本次只验证 Inbox 的 CLI 传输。正式安装宿主是否继承环境变量、多轮模型是否完整接收、token 和端到端成本尚未测量。

English verdict: APPROVE at dddc390. The opted-in 64K reader reduces calls without changing captured bytes, original cursors, or the 12K default and opener. Exact and integrated File/SQLite CLI coverage and same-capture recovery pass. The eight older agenda fixture failures reproduce on the base and pass on the current integration.

@loopx-agent
loopx-agent merged commit eefc016 into main Nov 21, 2026
28 of 36 checks passed
@loopx-agent
loopx-agent deleted the codex/inbox-recovery-page-budget branch November 21, 2026 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant